﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace ENG.PSSAirbusSoundExtender
{
  public class ASystem
  {
    #region Nested

    public enum eStatus
    {
      Off,
      Unpowered,
      On
    }

    #endregion Nested

    #region Events

    public delegate void IsOnChangedHandler(ASystem sender);
    public event IsOnChangedHandler IsOnChanged;

    public delegate void StatusChangedHandler(ASystem sender);
    public event StatusChangedHandler StatusChanged;

    #endregion Events

    #region Properties

    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
    private string _Name;
    ///<summary>
    /// Sets/gets Name value.
    ///</summary>
    public string Name
    {
      get
      {
        return (_Name);
      }
      set
      {
        _Name = value;
      }
    }

    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
    private EButton _StartButton;
    ///<summary>
    /// Sets/gets StartButton value.
    ///</summary>
    public EButton StartButton
    {
      get
      {
        return (_StartButton);
      }
      set
      {
        _StartButton = value;
      }
    }

    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
    private EButton _StopButton;
    public EButton StopButton
    {
      get
      {
        return (_StopButton);
      }
      set
      {
        _StopButton = value;
      }
    }

    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
    private int _MinBatteryCountToRun;
    ///<summary>
    /// Sets/gets MinBatteryCountToRun value.
    ///</summary>
    public int MinBatteryCountToRun
    {
      get
      {
        return (_MinBatteryCountToRun);
      }
      set
      {
        _MinBatteryCountToRun = value;
      }
    }

    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
    [NonSerialized()]
    private bool _IsOn = false;
    ///<summary>
    /// Sets/gets Status value.
    ///</summary>
    public bool IsOn
    {
      get
      {
        return (_IsOn);
      }
      set
      {
        if (value != _IsOn)
          _IsOn = value;
        if (IsOnChanged != null)
          IsOnChanged(this);
      }
    }

    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
    private bool _DefaultIsOn = false;
    ///<summary>
    /// Sets/gets DefaultIsOn value.
    ///</summary>
    public bool DefaultIsOn
    {
      get
      {
        return (_DefaultIsOn);
      }
      set
      {
        _DefaultIsOn = value;
      }
    }

    public bool HasVoice
    {
      get
      {
        return
          !string.IsNullOrEmpty(StartVoice) || !string.IsNullOrEmpty(GoVoice);
      }
    }

    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
    private string _StartVoice;
    ///<summary>
    /// Sets/gets StartVoice value.
    ///</summary>
    public string StartVoice
    {
      get
      {
        return (_StartVoice);
      }
      set
      {
        _StartVoice = value;
      }
    }

    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
    private string _GoVoice;
    ///<summary>
    /// Sets/gets GoVoice value.
    ///</summary>
    public string GoVoice
    {
      get
      {
        return (_GoVoice);
      }
      set
      {
        _GoVoice = value;
      }
    }

    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
    private bool _IsBattery;
    ///<summary>
    /// Sets/gets IsBattery value.
    ///</summary>
    public bool IsBattery
    {
      get
      {
        return (_IsBattery);
      }
      set
      {
        _IsBattery = value;
      }
    }

    [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
    [NonSerialized()]
    private eStatus _Status = eStatus.Off;
    ///<summary>
    /// Sets/gets Status value.
    ///</summary>
    public eStatus Status
    {
      get
      {
        return (_Status);
      }
      set
      {
        if (value != _Status)
        {
          _Status = value;
          if (StatusChanged != null)
            StatusChanged(this);
        }
      }
    }

    #endregion Properties

    #region .ctors


    public ASystem() { }

    public ASystem(string name, bool isBattery, EButton startButton, string goVoice)
      : this(name, isBattery, startButton, startButton, null, goVoice) { }

    public ASystem(string name, bool isBattery, EButton startButton, EButton stopButton, string startVoice, string goVoice)
    {
      this.Name = name;
      this.StartButton = startButton;
      this.StopButton = stopButton;
      this.StartVoice = startVoice;
      this.GoVoice = goVoice;
    }

    #endregion .ctors

    #region Methods

    public void Switch()
    {
      IsOn = !IsOn;
    }
    public bool TrySwitch(System.Drawing.Point point)
    {
      bool ret = false;

      if (IsOn)
      {
        if (StopButton.IsIn(point))
          IsOn = false;
        ret = true;
      }
      else
      {
        if (StartButton.IsIn(point))
          IsOn = true;
        ret = true;
      }

      return ret;
    }

    public void Reset()
    {
      this.IsOn = this.DefaultIsOn;
    }

    #endregion Methods

  }
}
